﻿using System;
using System.Data;
using System.Collections;
using CE.Database;

/// <summary>
/// Summary description for  ProvidersCarMoreDetailDB
/// </summary>
/// 
namespace CE.CarInsurance
{
    public class ProvidersCarMoreDetailDB
    {
        public ProvidersCarMoreDetailDB()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public Int64 Insert(ProvidersCarMoreDetail providerscarmoredetail)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "sprocCarMoreDetailInsertUpdateSingleItemAllProviders";

            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@CECarMoreDetailId", providerscarmoredetail.CECarMoreDetailId);
            _sPara.Add("@CECarId", providerscarmoredetail.CECarId);
            _sPara.Add("@ProviderCompanyId", providerscarmoredetail.ProviderCompanyId);
            _sPara.Add("@AnnualPremium", providerscarmoredetail.AnnualPremium);
            _sPara.Add("@TermPremium", providerscarmoredetail.TermPremium);
            _sPara.Add("@Name", providerscarmoredetail.Name);
            _sPara.Add("@IdentificationNo", providerscarmoredetail.IdentificationNo);
            _sPara.Add("@Occupation", providerscarmoredetail.Occupation);
            _sPara.Add("@ContactNo", providerscarmoredetail.ContactNo);
            _sPara.Add("@OfficePhoneNo", providerscarmoredetail.OfficePhoneNo);
            //_sPara.Add("@LicenseNo", providerscarmoredetail.LicenseNo);
            _sPara.Add("@BeneficiaryName", providerscarmoredetail.BeneficiaryName);

            _sPara.Add("@CarPlate", providerscarmoredetail.CarPlate);
            _sPara.Add("@CarPlateProvince", providerscarmoredetail.CarPlateProvince);
            _sPara.Add("@PresentAddress", providerscarmoredetail.PresentAddress);
            _sPara.Add("@SubDistrict", providerscarmoredetail.SubDistrict);
            _sPara.Add("@District", providerscarmoredetail.District);
            _sPara.Add("@Province", providerscarmoredetail.Province);
            _sPara.Add("@PostalCode", providerscarmoredetail.PostalCode);
            _sPara.Add("@IsMailingAddressDiff", providerscarmoredetail.IsMailingAddressDiff);
            _sPara.Add("@MailingAddress", providerscarmoredetail.MailingAddress);
            _sPara.Add("@MailingSubDistrict", providerscarmoredetail.MailingSubDistrict);
            _sPara.Add("@MailingDistrict", providerscarmoredetail.MailingDistrict);
            _sPara.Add("@MailingProvince", providerscarmoredetail.MailingProvince);
            _sPara.Add("@MailingPostalCode", providerscarmoredetail.MailingPostalCode);
            _sPara.Add("@EngineNumber", providerscarmoredetail.EngineNumber); //Sakthi on 24 Jun 2011
            _sPara.Add("@ChassisNumber", providerscarmoredetail.ChassisNumber); //Sakthi on 24 Jun 2011
            //_sPara.Add("@IsRegisteredOwner", providerscarmoredetail.IsRegisteredOwner); //Sakthi on 24 Jun 2011
            _sPara.Add("@IsCTPL", providerscarmoredetail.IsCTPL);
            _sPara.Add("@CTPL", providerscarmoredetail.CTPL);

            /*_sPara.Add("@No", providerscarmoredetail.No);
            _sPara.Add("@Soi", providerscarmoredetail.Soi);
            _sPara.Add("@Subzone", providerscarmoredetail.Subzone);
            _sPara.Add("@Province", providerscarmoredetail.Province);
            _sPara.Add("@Building", providerscarmoredetail.Building);
            _sPara.Add("@Street", providerscarmoredetail.Street);
            _sPara.Add("@District", providerscarmoredetail.District);
            _sPara.Add("@PostalCode", providerscarmoredetail.PostalCode);
            _sPara.Add("@IsDifferentAddress", providerscarmoredetail.IsDifferentAddress);
            _sPara.Add("@NoMailing", providerscarmoredetail.NoMailing);
            _sPara.Add("@SoiMailing", providerscarmoredetail.SoiMailing);
            _sPara.Add("@SubzoneMailing", providerscarmoredetail.SubzoneMailing);
            _sPara.Add("@ProvinceMailing", providerscarmoredetail.ProvinceMailing);
            _sPara.Add("@BuildingMailing", providerscarmoredetail.BuildingMailing);
            _sPara.Add("@StreetMailing", providerscarmoredetail.StreetMailing);
            _sPara.Add("@DistrictMailing", providerscarmoredetail.DistrictMailing);
            _sPara.Add("@PostalCodeMailing", providerscarmoredetail.PostalCodeMailing);
            _sPara.Add("@VehicleNo", providerscarmoredetail.VehicleNo);
            _sPara.Add("@EngineNo", providerscarmoredetail.EngineNo);
            _sPara.Add("@ChassisNo", providerscarmoredetail.ChassisNo);
            _sPara.Add("@VehicleColor", providerscarmoredetail.VehicleColor);
            _sPara.Add("@VehicleProvince", providerscarmoredetail.VehicleProvince);
            _sPara.Add("@PolicyStartDate", providerscarmoredetail.PolicyStartDate); */
            _sPara.Add("@PaymentOption", providerscarmoredetail.PaymentOption);
            _sPara.Add("@PaymentType", providerscarmoredetail.PaymentType);
            _sPara.Add("@PaymentBank", providerscarmoredetail.PaymentBank); //Sakthi on 24 Jun 2011

            _sPara.Add("@OrderRefNoId", providerscarmoredetail.OrderRefNoId);
            _sPara.Add("@OrderRefNo", providerscarmoredetail.OrderRefNo);
            _sPara.Add("@PaymentStatus", providerscarmoredetail.PaymentStatus);

            _sPara.Add("@QuoteRefNo", providerscarmoredetail.QuoteRefNo);
            _sPara.Add("@RefCEUserId", providerscarmoredetail.RefCEUserId);
            _sPara.Add("@ViewedDetailId", providerscarmoredetail.ViewedDetailId);
            _sPara.Add("@CarResultId", providerscarmoredetail.CarResultId);
            _sPara.Add("@Ninfo4", providerscarmoredetail.Ninfo4); // For AgentId
            _sPara.Add("@Ninfo5", providerscarmoredetail.Ninfo5); // Submission
            _sPara.Add("@Status", providerscarmoredetail.Status);
            _sPara.Add("@Ninfo1", providerscarmoredetail.Ninfo1);
            _sPara.Add("@Info1", providerscarmoredetail.Info1);
            _sPara.Add("@Info2", providerscarmoredetail.Info2);

            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public ProvidersCarMoreDetail GetCarMoreDetail(Int64 CarId, Int64 CEUserId, Int64 ProviderCompanyId)
        {
             ProvidersCarMoreDetail _providerscarmoredetail = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocCarMoreDetailSelectSingleItemAllProviders";

            SortedList _spara = new SortedList();
            _spara.Add("@CECarID", CarId);
            _spara.Add("@RefCEUserId", CEUserId);
            _spara.Add("@ProviderCompanyId", ProviderCompanyId);
            DataTable _dt = _db.GetDataTableBySP(_spName, _spara);
            if (_dt != null)
            {
                if (_dt.Rows.Count > 0)
                {
                    _providerscarmoredetail = new  ProvidersCarMoreDetail();
                    _providerscarmoredetail = FillDataRecord(_dt);
                }
            }
            return _providerscarmoredetail;
        }

        private  ProvidersCarMoreDetail FillDataRecord(DataTable myDataTable)
        {
             ProvidersCarMoreDetail myCarMoreDetail = new  ProvidersCarMoreDetail();
            myCarMoreDetail.CECarMoreDetailId = Convert.ToInt64(myDataTable.Rows[0]["CECarMoreDetailId"].ToString());
            myCarMoreDetail.CECarId = Convert.ToInt64(myDataTable.Rows[0]["CECarId"].ToString());
            myCarMoreDetail.ProviderCompanyId = Convert.ToInt64(myDataTable.Rows[0]["ProviderCompanyId"].ToString());
            myCarMoreDetail.AnnualPremium = Convert.ToSingle(myDataTable.Rows[0]["AnnualPremium"].ToString());
            myCarMoreDetail.TermPremium = Convert.ToSingle(myDataTable.Rows[0]["TermPremium"].ToString());
            myCarMoreDetail.Name = myDataTable.Rows[0]["Name"].ToString();
            if (myDataTable.Rows[0]["IdentificationNo"] != null)
            {
                myCarMoreDetail.IdentificationNo = myDataTable.Rows[0]["IdentificationNo"].ToString();
            }
            myCarMoreDetail.Occupation = myDataTable.Rows[0]["Occupation"].ToString();
            myCarMoreDetail.ContactNo = myDataTable.Rows[0]["ContactNo"].ToString();
            myCarMoreDetail.OfficePhoneNo = myDataTable.Rows[0]["OfficePhoneNo"].ToString();
            //myCarMoreDetail.LicenseNo = myDataTable.Rows[0]["LicenseNo"].ToString();
            myCarMoreDetail.BeneficiaryName = myDataTable.Rows[0]["BeneficiaryName"].ToString();

            myCarMoreDetail.CarPlate = myDataTable.Rows[0]["CarPlate"].ToString();
            myCarMoreDetail.CarPlateProvince = myDataTable.Rows[0]["CarPlateProvince"].ToString();
            myCarMoreDetail.PresentAddress = myDataTable.Rows[0]["PresentAddress"].ToString();
            myCarMoreDetail.SubDistrict = myDataTable.Rows[0]["SubDistrict"].ToString();
            myCarMoreDetail.District = myDataTable.Rows[0]["District"].ToString();
            myCarMoreDetail.Province = myDataTable.Rows[0]["Province"].ToString();
            myCarMoreDetail.PostalCode = myDataTable.Rows[0]["PostalCode"].ToString();
            myCarMoreDetail.IsMailingAddressDiff = Convert.ToBoolean(myDataTable.Rows[0]["IsMailingAddressDiff"].ToString());
            myCarMoreDetail.MailingAddress = myDataTable.Rows[0]["MailingAddress"].ToString();
            myCarMoreDetail.MailingSubDistrict = myDataTable.Rows[0]["MailingSubDistrict"].ToString();
            myCarMoreDetail.MailingDistrict = myDataTable.Rows[0]["MailingDistrict"].ToString();
            myCarMoreDetail.MailingProvince = myDataTable.Rows[0]["MailingProvince"].ToString();
            myCarMoreDetail.MailingPostalCode = myDataTable.Rows[0]["MailingPostalCode"].ToString();
            myCarMoreDetail.EngineNumber = myDataTable.Rows[0]["EngineNumber"].ToString(); //Sakthi on 24 Jun 2011
            myCarMoreDetail.ChassisNumber = myDataTable.Rows[0]["ChassisNumber"].ToString(); //Sakthi on 24 Jun 2011
            //myCarMoreDetail.IsRegisteredOwner = Convert.ToBoolean(myDataTable.Rows[0]["IsRegisteredOwner"].ToString());//Sakthi on 24 Jun 2011
            myCarMoreDetail.IsCTPL = Convert.ToBoolean(myDataTable.Rows[0]["IsCTPL"].ToString());
            myCarMoreDetail.CTPL = Convert.ToSingle(myDataTable.Rows[0]["CTPL"].ToString());

            /*myCarMoreDetail.No = myDataTable.Rows[0]["No"].ToString();
            myCarMoreDetail.Soi = myDataTable.Rows[0]["Soi"].ToString();
            myCarMoreDetail.Subzone = myDataTable.Rows[0]["Subzone"].ToString();
            myCarMoreDetail.Province = myDataTable.Rows[0]["Province"].ToString();
            myCarMoreDetail.Building = myDataTable.Rows[0]["Building"].ToString();
            myCarMoreDetail.Street = myDataTable.Rows[0]["Street"].ToString();
            myCarMoreDetail.District = myDataTable.Rows[0]["District"].ToString();
            myCarMoreDetail.PostalCode = myDataTable.Rows[0]["PostalCode"].ToString();
            myCarMoreDetail.IsDifferentAddress = Convert.ToBoolean(myDataTable.Rows[0]["IsDifferentAddress"].ToString());
            myCarMoreDetail.NoMailing = myDataTable.Rows[0]["NoMailing"].ToString();
            myCarMoreDetail.SoiMailing = myDataTable.Rows[0]["SoiMailing"].ToString();
            myCarMoreDetail.SubzoneMailing = myDataTable.Rows[0]["SubzoneMailing"].ToString();
            myCarMoreDetail.ProvinceMailing = myDataTable.Rows[0]["ProvinceMailing"].ToString();
            myCarMoreDetail.BuildingMailing = myDataTable.Rows[0]["BuildingMailing"].ToString();
            myCarMoreDetail.StreetMailing = myDataTable.Rows[0]["StreetMailing"].ToString();
            myCarMoreDetail.DistrictMailing = myDataTable.Rows[0]["DistrictMailing"].ToString();
            myCarMoreDetail.PostalCodeMailing = myDataTable.Rows[0]["PostalCodeMailing"].ToString();
            myCarMoreDetail.VehicleNo = myDataTable.Rows[0]["VehicleNo"].ToString();
            myCarMoreDetail.EngineNo = myDataTable.Rows[0]["EngineNo"].ToString();
            myCarMoreDetail.ChassisNo = myDataTable.Rows[0]["ChassisNo"].ToString();
            myCarMoreDetail.VehicleColor = myDataTable.Rows[0]["VehicleColor"].ToString();
            myCarMoreDetail.VehicleProvince = myDataTable.Rows[0]["VehicleProvince"].ToString();
            myCarMoreDetail.PolicyStartDate = Convert.ToDateTime(myDataTable.Rows[0]["PolicyStartDate"].ToString());*/

            myCarMoreDetail.PaymentOption = myDataTable.Rows[0]["PaymentOption"].ToString();
            myCarMoreDetail.PaymentType = myDataTable.Rows[0]["PaymentType"].ToString();
            myCarMoreDetail.PaymentBank = myDataTable.Rows[0]["PaymentBank"].ToString();//Sakthi on 24 Jun 2011
            myCarMoreDetail.QuoteRefNo = myDataTable.Rows[0]["QuoteRefNo"].ToString();
            myCarMoreDetail.RefCEUserId = Convert.ToInt64(myDataTable.Rows[0]["RefCEUserId"].ToString());
            myCarMoreDetail.CarResultId = Convert.ToInt64(myDataTable.Rows[0]["CarResultId"].ToString());
            if (myDataTable.Rows[0]["Ninfo4"] != null)
            {
                myCarMoreDetail.Ninfo4 = Convert.ToInt64(myDataTable.Rows[0]["Ninfo4"].ToString());
            }
            if (myDataTable.Rows[0]["Ninfo5"] != null)
            {
                myCarMoreDetail.Ninfo5 = Convert.ToInt32(myDataTable.Rows[0]["Ninfo5"].ToString());
            }
            myCarMoreDetail.Status = Convert.ToBoolean(myDataTable.Rows[0]["Status"].ToString());


            return myCarMoreDetail;
        }

        public DataSet GetCarPolicyDetails(Int64 CarId, Int64 CEId, Int64 CXCoverTypeId, Int64 ProviderCompanyId)
        {
            DataSet _result = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocCarInsuranceTHSelectedPlanSingleItem";

            SortedList _spara = new SortedList();
            _spara.Add("@CECarId", CarId);
            _spara.Add("@RefCEUserId", CEId);
            _spara.Add("@CITempResultId", CXCoverTypeId);
            _spara.Add("@ProviderCompanyId", ProviderCompanyId);


            using (DataSet _ds = _db.GetDataSet(_spName, _spara))
            {
                if (_ds != null && _ds.Tables.Count > 0 && _ds.Tables[0].Rows.Count > 0)
                {
                    _result = _ds;
                }
            }
            return _result;
        }

        public Int64 CheckConfirmStatus(Int64 CarId, string ResultType)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "sprocCheckUserConfirmStatus";

            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@CECarId", CarId);
            _sPara.Add("@ResultType", ResultType);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

    }
}